﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsSeekDAL.cs
/// 作  者：SAM
/// 时  间：2006.11.05
/// 说  明：ClsSeekDAL类用于贴现/兑现
/// </summary>
public class ClsSeekDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    //获取贴现/兑现信息
    public DataSet GetSeek(string o_id, int p_type)
    {

        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);            
        
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetSeek", con);
        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@o_id", o_id);//单据编号
        dat.SelectCommand.Parameters.Add("@p_type", p_type);//贴现/兑现

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    //增加贴现/兑现信息
    public Boolean AddSeek(string o_id, int p_type, string p_id, DateTime p_date, string p_bank, decimal p_lv, decimal p_value, decimal p_fy, decimal p_money, string bsUnit, decimal bsje, decimal lx, bool is_c_lx, bool is_c_fy, string oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddSeek", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@o_id", SqlDbType.NVarChar, 30);
        com.Parameters["@o_id"].Value = o_id;
        com.Parameters.Add("@p_type", SqlDbType.NVarChar, 30);
        com.Parameters["@p_type"].Value = p_type;
        com.Parameters.Add("@p_id", SqlDbType.NVarChar, 30);
        com.Parameters["@p_id"].Value = p_id;
        com.Parameters.Add("@p_date", SqlDbType.DateTime);
        com.Parameters["@p_date"].Value = p_date;
        com.Parameters.Add("@p_bank", SqlDbType.NVarChar,255);
        com.Parameters["@p_bank"].Value = p_bank;
        com.Parameters.Add("@p_lv", SqlDbType.Decimal);
        com.Parameters["@p_lv"].Value = p_lv;
        com.Parameters.Add("@p_value", SqlDbType.Decimal);
        com.Parameters["@p_value"].Value = p_value;
        com.Parameters.Add("@p_fy", SqlDbType.Decimal);
        com.Parameters["@p_fy"].Value = p_fy;
        com.Parameters.Add("@p_money", SqlDbType.Decimal);
        com.Parameters["@p_money"].Value = p_money;
        com.Parameters.Add("@bsUnit", SqlDbType.NVarChar, 255);
        com.Parameters["@bsUnit"].Value = bsUnit;
        com.Parameters.Add("@bsje", SqlDbType.Decimal);
        com.Parameters["@bsje"].Value = bsje;
        com.Parameters.Add("@lx", SqlDbType.Decimal);
        com.Parameters["@lx"].Value = lx;
        com.Parameters.Add("@is_c_lx", SqlDbType.Bit);
        com.Parameters["@is_c_lx"].Value = is_c_lx;
        com.Parameters.Add("@is_c_fy", SqlDbType.Bit);
        com.Parameters["@is_c_fy"].Value = is_c_fy;

        com.Parameters.Add("@oper", SqlDbType.NVarChar, 60);
        com.Parameters["@oper"].Value = oper;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    //修改贴现/兑现信息
    public Boolean UpdateSeek(string o_id, int p_type, string p_id, DateTime p_date, string p_bank, decimal p_lv, decimal p_value, decimal p_fy, decimal p_money, string bsUnit, decimal bsje, decimal lx, bool is_c_lx, bool is_c_fy, string oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpdateSeek", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@o_id", SqlDbType.NVarChar, 30);
        com.Parameters["@o_id"].Value = o_id;
        com.Parameters.Add("@p_type", SqlDbType.NVarChar, 30);
        com.Parameters["@p_type"].Value = p_type;
        com.Parameters.Add("@p_id", SqlDbType.NVarChar, 30);
        com.Parameters["@p_id"].Value = p_id;
        com.Parameters.Add("@p_date", SqlDbType.DateTime);
        com.Parameters["@p_date"].Value = p_date;
        com.Parameters.Add("@p_bank", SqlDbType.NVarChar, 255);
        com.Parameters["@p_bank"].Value = p_bank;
        com.Parameters.Add("@p_lv", SqlDbType.Decimal);
        com.Parameters["@p_lv"].Value = p_lv;
        com.Parameters.Add("@p_value", SqlDbType.Decimal);
        com.Parameters["@p_value"].Value = p_value;
        com.Parameters.Add("@p_fy", SqlDbType.Decimal);
        com.Parameters["@p_fy"].Value = p_fy;
        com.Parameters.Add("@p_money", SqlDbType.Decimal);
        com.Parameters["@p_money"].Value = p_money;
        com.Parameters.Add("@bsUnit", SqlDbType.NVarChar, 255);
        com.Parameters["@bsUnit"].Value = bsUnit;
        com.Parameters.Add("@bsje", SqlDbType.Decimal);
        com.Parameters["@bsje"].Value = bsje;
        com.Parameters.Add("@lx", SqlDbType.Decimal);
        com.Parameters["@lx"].Value = lx;
        com.Parameters.Add("@is_c_lx", SqlDbType.Bit);
        com.Parameters["@is_c_lx"].Value = is_c_lx;
        com.Parameters.Add("@is_c_fy", SqlDbType.Bit);
        com.Parameters["@is_c_fy"].Value = is_c_fy;

        com.Parameters.Add("@oper", SqlDbType.NVarChar, 60);
        com.Parameters["@oper"].Value = oper;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    //删除贴现/兑现信息
    public Boolean DeleteSeek(int p_type, string o_id)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteSeek", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@p_type", SqlDbType.Int);
        com.Parameters["@p_type"].Value = p_type;
        com.Parameters.Add("@o_id", SqlDbType.NVarChar, 30);
        com.Parameters["@o_id"].Value = o_id;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }
}
